package Rainwater.Service.impl;

import Rainwater.Service.PointService;
import Rainwater.baen.pojo.Point;
import Rainwater.baen.pojo.PointGroup;
import Rainwater.baen.pojo.User;
import Rainwater.baen.vo.*;
import Rainwater.mapper.PointMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @author cfy
 * @date 2024/10/17
 **/
@Service
public class PointServiceImpl implements PointService {
    @Autowired
    private PointMapper pointMapper;
    @Override
    public ArrayList<PointVo> getPoints(Integer pageNumber, String search) {

        //每页条数
        int number = 10;
        //跳过条数
        int page = (pageNumber-1)*number;
        if (search==null||search.equals("null")){
            search=null;
        }
        ArrayList<Point> points = pointMapper.selectAllPager(number, page, search);
        ArrayList<PointVo> pointVos = new ArrayList<>();
        for (Point point:points) {
//            System.out.println(point);
            pointVos.add(new PointVo(
                    point.getPId(),
                    point.getPName(),
                    point.getAddress()));
        }
        return pointVos;
    }

    @Override
    public ArrayList<PointGroup> getGroup() {
        return pointMapper.groupProvince();
    }

    @Override
    public ArrayList<IndexPointVo> getIndexPoints() {
        ArrayList<Point> points = pointMapper.selectAll();
        ArrayList<IndexPointVo> indexPointVos = new ArrayList<>();
        for (Point p:points) {
            indexPointVos.add(new IndexPointVo(p.getPId(),p.getPX(),p.getPY()));
        }
        return indexPointVos;
    }

    @Override
    public boolean deletePoint(Integer id) {
        return false;
    }

    @Override
    public PointVo getPointById(Integer id) {

        return null;
    }

    @Override
    public IndexMapPointVo getMapPoint(Integer id) {
        IndexMapPointVo pointVo = new IndexMapPointVo("山西省","12","2","1200");
        return pointVo;
    }

    @Override
    public ArrayList<AnalysisPointVo> getPointNames() {
        ArrayList<AnalysisPointVo> lists = new ArrayList<>();
        lists.add(new AnalysisPointVo(1,"aa"));
        lists.add(new AnalysisPointVo(2,"bb"));
        lists.add(new AnalysisPointVo(3,"cc"));
        return lists;
    }
}
